﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarvellousWorks.PracticalPatternNet8.Concept.Iterating;

public class ObjectWithName
{
    private string _name;
    public ObjectWithName(string name)
    {
        _name = name;
    }
    public override string ToString()
    {
        return _name;
    }
}

public class BinaryTreeNode:ObjectWithName
{
    //private string name;
    public BinaryTreeNode(string name):base(name) 
    {
        
    }

    public BinaryTreeNode Left = null;
    public BinaryTreeNode Right = null;
    public IEnumerator<ObjectWithName> GetEnumerator()
    {
        yield return this;
        if (Left != null)
        {
            foreach (ObjectWithName item in Left)
            {
                yield return item;
            }
        }
        if (Right != null)
        {
            foreach (ObjectWithName item in Right)
            {
                yield return item;
            }
        }
    }
}

